package com.itheima.servlet;

import com.alibaba.fastjson.JSON;
import com.itheima.bean.Brand;
import com.itheima.service.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/UpdateBrandServlet")
public class UpdateBrandServlet extends HttpServlet {
    //修改品牌信息

    private final BrandService brandService = new BrandService();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获得闯入的品牌对象
        String json = request.getReader().readLine();
        Brand brand = JSON.parseObject(json, Brand.class);

        //转为brand对象
        //修改品牌
        int update = brandService.update(brand);
        PrintWriter out = response.getWriter();
        if(update==0){
            out.print("false");
        }else {
            out.print("true");
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        int i = Integer.parseInt(id);

    }
}
